/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.ts.controller;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.xy.biz.ts.domain.req.examinationRecord.GetExaminationRecordByTrainIdRequest;
import com.xy.biz.ts.domain.req.examinationRecord.GetExaminationRecordRequest;
import com.xy.biz.ts.domain.req.examinationRecord.ListExaminationRecordRequest;
import com.xy.biz.ts.domain.resp.GetTrainByClassifyResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;

import com.xy.biz.ts.domain.resp.GetExaminationRecordResponse;
import com.xy.biz.ts.domain.req.SaveExaminationRecordRequest;
import com.xy.biz.ts.domain.query.ExaminationRecordQuery;
import com.xy.biz.ts.domain.converter.ExaminationRecordConverter;
import com.xy.biz.ts.client.ExaminationRecordClient;
import com.xy.biz.ts.service.ExaminationRecordService;

/**
 *
 *
 * @author wcs
 * @date 2021-3-10
 */
@Api(tags = "培训流程服务-记录")
@Slf4j
@RequestMapping("/api/ts/examination_record")
@RestController
public class ExaminationRecordController implements ExaminationRecordClient {

    @Autowired
    private ExaminationRecordService examinationRecordService;

    @Validatable
    @PostMapping(value = "/delete")
    public Result<?> deleteExaminationRecord(@RequestBody GetExaminationRecordRequest request) {
        examinationRecordService.deleteExaminationRecord(request.getExaminationRecordId());
        return Result.success();
    }

    @Validatable
    @PostMapping(value = "/get_examination_record")
    @Override
    public Result<?> getExaminationRecord(@RequestBody GetExaminationRecordRequest request) {
        return examinationRecordService.getExaminationRecord(request.getExaminationRecordId());
    }

    @Validatable
    @PostMapping(value = "/get_examination_record_by_train_id")
    @Override
    public Result<List<GetExaminationRecordResponse>> listExaminationRecordByTrainId(@RequestBody GetExaminationRecordByTrainIdRequest request) {
        return Result.success(examinationRecordService.listExaminationRecordByTrainId(request));
    }

    @PostMapping(value = "/page")
    @Override
    public Result<Page<GetExaminationRecordResponse>> pageExaminationRecord(@RequestBody ListExaminationRecordRequest request) {
        ExaminationRecordQuery query = ExaminationRecordConverter.toQuery(request);
        List<GetExaminationRecordResponse> list = ExaminationRecordConverter.toResponse(examinationRecordService.listExaminationRecord(query));
        int count = examinationRecordService.countExaminationRecord(query);
        return Result.success(new Page<>(list, count));
    }

    /**
     * 提交试卷
     * @param request
     * @return
     */
    @PostMapping(value = "/save")
    public Result<?> saveExaminationRecord(@RequestBody SaveExaminationRecordRequest request) {
        return examinationRecordService.saveExaminationRecord(request);
    }

    /**
     * 批改试卷
     * @param request
     * @return
     */
    @PostMapping(value = "/correct")
    public Result<?> correctExaminationRecord(@RequestBody SaveExaminationRecordRequest request) {
        return examinationRecordService.correctExaminationRecord(request);
    }

}
